<template>
  <div class="dashboard-container">
    <aside class="aside-style">
      <el-row>
        <el-col :span="2">
          <el-button type="primary" size="mini" icon="el-icon-circle-plus" @click="addNewDriver">新增</el-button>
        </el-col>
      </el-row>
    </aside>
    <el-table
      :data="list"
      border
      highlight-current-row
      width="100%"
      style="margin-top: 20px;font-size:12px"
    >
      <el-table-column label="车辆" align="center" prop="car_name" />
      <el-table-column prop="car_num" label="车牌号" align="center" />
      <el-table-column label="乘坐人数" align="center" prop="limit" />
      <el-table-column label="费用" align="center">
        <template slot-scope="scope">
          {{ scope.row.integral }} / 公里
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="resetFun(scope.row)">修改</el-button>
          <del-confirm title="是否确认删除该车辆信息？" @onConfirm="delFun(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" pagination="paginationFun" />
    <addDialog ref="add-dialog" @reloadFun="reloadFun" />
  </div>
</template>

<script>
import pagination from '@/components/Pagination'
import delConfirm from '@/components/DelConfirm'
import addDialog from '../carControl/components/car-dialog'
import { getCarListApi, deleteCarApi } from '@/api/main'
export default {
  components: {
    pagination,
    delConfirm,
    addDialog
  },
  data() {
    return {
      list: [],
      total: 0,
      department: [],
      p: 1,
      num: 10
    }
  },
  created() {
    this.getCarlist()
  },
  methods: {
    getCarlist() {
      const data = {
        status: '1',
        p: this.p,
        limit: this.num
      }
      getCarListApi(data).then(res => {
        console.log('res', res)
        if (res.list.length) {
          this.list = res.list
          this.total = Number(res.count)
        }
        console.log(this.list, this.total)
      })
    },
    addNewDriver() {
      this.$refs['add-dialog'].dialogVisible = true
      this.$refs['add-dialog'].form = {
        car_name: '',
        car_num: '',
        id: '',
        limit: '',
        integral: ''
      }
      this.$refs['add-dialog'].upType = 1
      this.$refs['add-dialog'].title = '新增'
    },
    resetFun(row) {
      this.$refs['add-dialog'].dialogVisible = true
      this.$refs['add-dialog'].form = row
      this.$refs['add-dialog'].upType = 2
      this.$refs['add-dialog'].title = '修改'
    },
    delFun(row) {
    //   console.log(row)
      deleteCarApi({ id: row.id }).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.getCarlist()
        }
      })
    },
    reloadFun() {
      this.getCarlist()
    },
    paginationFun(val) {
      this.p = val.page
      this.num = val.limit
      this.getCarlist()
    }
  }
}
</script>

<style lang="scss" scoped>
.img-style {
    width: 5opx;
    height:50px;
}
.dashboard {
    &-container {
        margin: 30px;
    }
    &-text {
        font-size: 30px;
        line-height: 46px;
    }
}
</style>
